package com.stu.service;

import com.stu.beans.Student;
import com.stu.dao.StuDao;

import java.util.List;

public class StuService {
    private StuDao stuDao = new StuDao();
    public boolean addStu(Student student) {
        return stuDao.addStu(student) > 0;
    }

    /**
     * 查询学生信息
     */
    public List<Student> queryStu(Student student) {
        if (student.getSno() != null && !student.getSno().isEmpty()){
            // 根据学号模糊查询
            student.setSno("%"+student.getSno()+"%");
            student.setName("%");
            student.setPhone("%");
            return stuDao.queryStu(student);
        }else if (student.getName() != null && !student.getName().isEmpty()){
            // 根据姓名模糊查询
            student.setSno("%");
            student.setName("%"+student.getName()+"%");
            student.setPhone("%");
            return stuDao.queryStu(student);
        }else if (student.getPhone() != null && !student.getPhone().isEmpty()){
            // 根据手机号模糊查询
            student.setSno("%");
            student.setName("%");
            student.setPhone("%"+student.getPhone()+"%");
            return stuDao.queryStu(student);
        }
        return null;
    }

    public List<Student> queryAll() {
        return stuDao.queryAll();
    }

    public boolean modifyStu(Student student) {
        return stuDao.modifyStu(student) > 0;
    }
}
